fix(ios): never default to a connected device on plain run-ios#2795
Open
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
Open
fix(ios): never default to a connected device on plain run-ios#2795azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
Conversation
…-native-community#2765) When neither --device nor --udid nor --simulator is supplied, run-ios now always targets a simulator (booted preferred, otherwise the fallback simulator) and ignores any connected physical device. The previous default counted physical devices as "booted" and installed the app on the iPhone alongside (or instead of) a simulator, which contradicted the docs and was unavoidable in modern Xcode where Wi-Fi device pairing cannot be disabled. Physical devices are still reachable via --device / --udid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2765 (continuation of #2254).
When
react-native run-iosis invoked without any of--device/--udid/--simulator, it should target a simulator (per the docs: "Builds your app and starts it on iOS simulator."). In practice the default path was installing the app on a connected physical iPhone instead. Modern Xcode no longer lets users disable Wi-Fi device pairing, so any developer who has ever paired an iPhone hits this every run.Root cause
packages/cli-platform-apple/src/commands/runCommand/createRun.ts, the no-flag branch:Two problems:
bootedDevicesparticipates in the no-flag default path at all.booted.length !== 0because of the iPhone, so the fallback-simulator branch is skipped and the build/install runs on the device — exactly the trace from the issue:Fix
Replace the no-flag block with simulator-only logic:
fallbackSimulator(computed earlier viagetFallbackSimulator(args)).runOnSimulatorexactly once with that target.--device/--udid, so users understand the change.Explicit paths (
--device,--udid,--simulator,--list-devices,--interactive) are unchanged — the fix only affects the no-flag default.Test Plan
Unit tests (added)
packages/cli-platform-apple/src/commands/runCommand/__tests__/createRun.test.tscovers:runOnSimulatoris called once with the fallback simulator;runOnDeviceis not called. (Direct repro of run-ios prioritizes devices over simulators, contradicting docs #2765.)runOnSimulatoris called once with the booted simulator;runOnDeviceis not called.--device "<name>"→runOnDeviceis called with the iPhone (regression guard for the explicit path).runOnSimulatoris called once with the fallback simulator (preserves prior behavior).yarn lintandyarn buildare also green.Manual repro
Using https://github.com/swrobel/cli-reproducer:
npx react-native run-ios→ expect a simulator to launch (e.g. iPhone 14 / first available), not the iPhone. The output now includesIgnoring connected device (<iPhone name>). Pass --device or --udid to install on a physical device.npx react-native run-ios --device "<iPhone name>"→ expect the iPhone path to still work end-to-end.Checklist
cli-platform-ios/README.mdalready describes this behavior — the fix brings code in line with the docs).react-nativecheckout — manual repro listed above; happy to add screenshots if useful.